/* Copyright (C) 2010 Fredrique Samuels, fredriquesamuels@gmail.com */

/*
  This program is free software; you can redistribute it and/or modify
  it under the terms of the GNU General Public License as published by
  the Free Software Foundation; either version 2 of the License, or
  (at your option) any later version.

  This program is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  GNU General Public License for more details.

  You should have received a copy of the GNU General Public License
  along with this program; if not, write to the Free Software
  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/

#ifndef TRI_CAMERA_H_
#define TRI_CAMERA_H_

#include "base/animate.h"
#include "base/vector.h"
#include "base/matrix.h"
#include "graphics.h"

namespace tri
{

enum{
	TRI_PERSPECTIVE,
	TRI_ORTHO
};
/**
 * Camera Entity. Does not derectly inherit tri::entity
 * but does maintain the same api. 
 */
class TCamera
{
public:
	TCamera();
	virtual ~TCamera();
	
	void setPosition(TVector v);
	void setRotation(TVector v);
	void setPosition(float x, float y, float z);
	void setRotation(float x, float y, float z);
	
	void setViewAngle(float a);
	void setAspectRatio(float a);
	
	void setLookAtVector(tri::TVector v);
	void setTargetLookAtVector(tri::TVector v,float t);
	
	TMatrix getModelMatrix();

	TVector getPosition();
	TVector getRotation();
	
	void applyPerspective();
	void applyView();
	void action();
	
	float getViewAngle();
	unsigned int getAspectRatio();
	unsigned int getCamID();
	
	
	void setViewMode(int);
	void setOrthoBounds(tri::TRectangle);
	tri::TRectangle getOrthoBounds();
	
	TCamera* getActiveCamera();
	
private:
	TAniVector m_Pos;
	TAniVector m_Rot;
	TAniVector m_LookAtPos;
	
	float m_ViewAngle;
	float m_AspectRatio;
	
	TMatrix m_ModelMatrix;
	
	static unsigned int s_UIDCount;
    unsigned int m_UID;
    
    int mViewMode;
    tri::TRectangle mOrthoBounds;
    
    static TCamera* s_ActiveCamera;
	
//	void setTargetPosition(vector* v,float t=1.0);
//	void setTargetPosition(float x,float y,float z,float t=1.0);
//	void setTargetRotation(vector* v,float t=1.0);
//	void setTargetRotation(float x,float y,float z,float t=1.0);
//	void setPosition(vector* v);
//	void setPosition(float x,float y,float z);
//	void setRotation(vector* v);
//	void setRotation(float x,float y,float z);
//	void setLookAt(vector* v);
//	void setTargetLookAt(vector* v,float t=1.0);
//	void action();
//	void apply_perspective();
//	void apply_view();
//	int get_cam_id();
//	void set_view_angle(float a);
//	void set_aspect_ratio(float ar);
//	float getViewAngle();
//	
//	tri::vector getPosition();
//	tri::vector getRotation();
//	void setPosition(tri::vector v);
//	void setRotation(tri::vector v);
//	
//	void get_model_matrix(tri::matrix* m);
//	tri::vector getAbsolutePosition();
//	
//	
//	void getInverseCameraRotationMatrix(tri::matrix* mat);
//	tri::vector getGlobalPosition(tri::vector v);
//	
	
//	
//private:
//	void calcLookAtFromRotation(vector r,vector p);
//	tri::matrix model_view_matrix;
//	tri::anivector position;
//	tri::anivector rotation;
//	tri::anivector focus_loc;
//	tri::vector last_rot;
//	tri::anivector look_at_pos;
//    float angle;
//    float aspectRatio;
//    
//    static int uid_count;
//    int uid;
//    int mViewMode;
//    tri::rectangle mOrthoBounds;
};

}

#endif /*CAMERA_H_*/
